package com.wsoft.manager;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsoft.entity.TsJobLogEntity;
import com.wsoft.mapper.TsJobLogMapper;
import com.wsoft.query.job.log.JobLogListQuery;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author z001
 * @Date 2024/10/23 09:09
 */
@Service
public class TsJobLogManager extends ServiceImpl<TsJobLogMapper, TsJobLogEntity> {

    @Override
    public boolean save(TsJobLogEntity entity) {
        return super.save(entity);
    }

    /**
     * 查询日志列表
     * @param param
     * @return
     */
    public List<TsJobLogEntity> listJobLog(JobLogListQuery param) {
        QueryWrapper<TsJobLogEntity> query = new QueryWrapper<>();
        query.lambda().eq(ObjUtil.isNotEmpty(param.getJobId()),TsJobLogEntity::getJobId,param.getJobId())
                .eq(StrUtil.isNotBlank(param.getName()),TsJobLogEntity::getName,param.getName())
                .eq(StrUtil.isNotBlank(param.getCode()),TsJobLogEntity::getCode,param.getCode())
                .eq(ObjUtil.isNotEmpty(param.getResult()),TsJobLogEntity::getResult,param.getResult())
                //按照执行时间倒序
                .orderByDesc(TsJobLogEntity::getStartTime);
        return list(query);
    }
}
